package com.sskj.mine;


import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.util.ClickUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.model.room.UserViewModel;
import com.sskj.mine.component.DaggerUserDataComponent;
import com.sskj.mine.presenter.MineVerifyResultActivityPresenter;
import com.sskj.mine.verify.VerifySecondActivity;

import javax.inject.Inject;

import butterknife.BindView;

@Route(path = RConfig.MINE_VERIFY_RESULT)  // 认证成功  --  认证失败界面
public class MineVerifyResultActivity extends BaseActivity<MineVerifyResultActivityPresenter> {

    @BindView(R2.id.verify_status)
    TextView verifyStatus;
    @BindView(R2.id.img)
    ImageView img;
    @BindView(R2.id.failed_reason)
    TextView failedReason;
    @BindView(R2.id.reset_verify)
    TextView resetVerify;
    @BindView(R2.id.verify_failed_rl)
    LinearLayout verifyFailedRl;
    @Autowired
    public boolean isSuccess;  // true 认证成功
    @Inject
    UserViewModel userViewModel;
    private UserData userData;


    @Override
    protected int getLayoutId() {
        return R.layout.mine_activity_verify_result;
    }

    @Override
    public MineVerifyResultActivityPresenter getPresenter() {
        return new MineVerifyResultActivityPresenter();
    }

    @Override
    public void initView() {
        ARouter.getInstance().inject(this);
        setTitle(isSuccess ? getString(R.string.mine_mineVerifyResultActivity1) : getString(R.string.mine_mineVerifyResultActivity2));
        DaggerUserDataComponent.create().inject(this);
        userViewModel.getUsers().observe(this, users -> {
            if (users != null && users.size() > 0) {
                userData = users.get(0);
                if (!isSuccess) {
                    failedReason.setText(getString(R.string.mine_mineVerifyResultActivity3) + userData.getAuth_msg());
                }
            } else {
                userData = null;
            }
        });
        if (isSuccess) {
            verifyStatus.setVisibility(View.VISIBLE);
            verifyFailedRl.setVisibility(View.GONE);
        } else {
            verifyStatus.setVisibility(View.GONE);
            verifyFailedRl.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    public void initEvent() {
        ClickUtil.click(resetVerify, () -> {
            VerifySecondActivity.start(this);
            finish();
        });

    }

    // 失败原因
    public void updateUi(String data) {
        failedReason.setText(getString(R.string.mine_mineVerifyResultActivity3) + data);
    }
}
